﻿// <copyright file="StringWriterWithEncoding.cs" company="Microsoft Corporation">
// Copyright (c) 2009 Microsoft Corporation All Rights Reserved
// </copyright>
// <author>http://bytes.com/topic/c-sharp/answers/307901-xmltextwriter-utf-8-a</author>
// <email>n/a</email>
// <date>2010-01-19</date>
// <summary>StringWriterWithEcoding class definition</summary>

namespace WebAnalyticsServiceWizard
{
    using System.Globalization;
    using System.IO;
    using System.Text;

    /// <summary>
    /// String writer with Encoding to write UTF-8 XML Text
    /// </summary>
    /// <remarks>From http://bytes.com/topic/c-sharp/answers/307901-xmltextwriter-utf-8-a</remarks>
    public class StringWriterWithEncoding : StringWriter
    {
        /// <summary>
        /// The encoding specified in the constructor
        /// </summary>
        private Encoding encoding;

        /// <summary>
        /// Initializes a new instance of the StringWriterWithEncoding class
        /// </summary>
        /// <param name="encoding">the encoding to use when writing the string</param>
        public StringWriterWithEncoding(Encoding encoding) :
            base(CultureInfo.InvariantCulture)
        {
            this.encoding = encoding;
        }

        /// <summary>
        /// Gets the encoding for the writer
        /// </summary>
        public override Encoding Encoding
        {
            get 
            { 
                return this.encoding; 
            }
        }
    }
}
